package com.dididoctor.doctor.Activity.Usercentre.MyPurse.InComeList;

import android.view.View;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Ui.customlistview.OnRefreshListener;
import com.dididoctor.doctor.Ui.customlistview.RefreshListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 张强
 * Created by Administrator on 2016/4/19.
 */
public class ComeInActivity extends EduActivity implements ComeInView {
    private TextView mTvTitle;
    private ImageView mBtnBack;
    private RefreshListView mlvMessage;
    private ComeInAdapter adapter;
    private ComeInPresenter presenter;
    private int pageIndex = 1;

    private List<ComeInBean> comeInBeans = new ArrayList<ComeInBean>();

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_message);
    }

    @Override
    public void init() {

        /**头部**/
        initTitleView();

        /** 界面**/
        initview();

    }

    private void initview() {

        mlvMessage = (RefreshListView) findViewById(R.id.lv_message);
        mlvMessage.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onPullDownRefresh() {
                pageIndex = 1;
                presenter.lunch(pageIndex);
            }

            @Override
            public void onLoadMoring() {
                pageIndex++;
                presenter.lunch(pageIndex);
            }

            @Override
            public void onScrollListener(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });
        mlvMessage.setHeadAndFoot(true, true);
        adapter = new ComeInAdapter(ComeInActivity.this, comeInBeans);
        mlvMessage.setAdapter(adapter);
        presenter = new ComeInPresenter(ComeInActivity.this, this);
        presenter.lunch(pageIndex);
    }

    private void initTitleView() {
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvTitle.setText("收入清单");
        mBtnBack = (ImageView) findViewById(R.id.btn_back);
    }

    @Override
    public void onClickEvent(View view) {

    }


    @Override
    public void getincomefail() {
        showToastMessage("网络连接失败，请检查您的网络设置");
        mlvMessage.onRefreshFinish();
    }

    @Override
    public void getincomesucced(List<ComeInBean> comeInBeans) {
        if (comeInBeans != null && comeInBeans.size() > 0) {
            if (pageIndex == 1) {
                this.comeInBeans.clear();
                adapter.setData(comeInBeans);
                mlvMessage.onRefreshFinish();
            } else {
                if (comeInBeans.size() < ConstantValue.LOAD_MESSAGE_COUNT) {
                    adapter.addData(comeInBeans);
                    mlvMessage.showNoMoreData();
                } else {
                    adapter.addData(comeInBeans);
                    mlvMessage.hideNoMoreData();
                }
            }
            adapter.notifyDataSetChanged();
        } else {
            if (pageIndex == 1) {
                mlvMessage.onRefreshFinish();
            } else {
                mlvMessage.showNoMoreData();
                adapter.notifyDataSetChanged();
            }
        }
    }
}
